package eerbaar.internal.game;

import eerbaar.area.IArea;
import eerbaar.elements.IElement;
import eerbaar.elements.extension.ElementFactory;
import eerbaar.elements.extension.IPoints;
import eerbaar.game.IGame;
import eerbaar.game.IGamePopulator;
import eerbaar.level.ILevel;
import eerbaar.position.IPosition;
import eerbaar.position.PositionFactory;

public class TrainingRoom extends Game implements IGame, IGamePopulator {

    public TrainingRoom() {
        //
    }

    public TrainingRoom(IArea area, ILevel level) {
        super(area, level);
    }

    @Override
    public void init() {
        super.init();
    }

    @Override
    public void populateContent(String inName, int inCount, int inPoints) {

        int y = getArea().getHeight();
        int x = getArea().getWidth();
        IPosition max = PositionFactory.createPosition(x, y);

        int count = 0;
        for (int i = 0; i < 100; i++) {

            IElement element = ElementFactory.createWithRandomPosition(inName,
                    max);

            IPoints ePoints = element.getExtension(IPoints.class);
            if (ePoints != null) {
                ePoints.setPoints(inPoints);
            }

            IPosition pos = element.getPosition();

            IElement[] tests = getArea().getElements(pos);
            if (tests.length > 0) {
                continue;
            }

            getArea().addElement(element);
            count++;
            if (count >= inCount) {
                break;
            }
        }
    }

}
